myApp.factory("loginService",function($http, $q) {
   
    return {
        isValidUser : isValidUser,
        isValidChef : isValidChef
    };

function isValidUser(userName) {
        var deferred = $q.defer();
        return $http({
            method : 'POST',
            url    : 'api/userlogin',
            headers: {
                'username': userName
            }
        }).success(function(respData) {
            deferred.resolve(respData);			
        }).error(function(errorData) {
            console.log("Error while retriving users. ");
        });
        return deferred.promise;
    }
    
    function isValidChef(userName) {
        var deferred = $q.defer();
        return $http({
            method : 'POST',
            url    : 'api/cheflogin',
            headers: {
                'username': userName
            }
        }).success(function(respData) {
            deferred.resolve(respData);			
        }).error(function(errorData) {
            console.log("Error while retriving users. ");
        });
        return deferred.promise;
    }
});